package com.egao.common.component.minio.controller;

import com.egao.common.component.minio.service.MinioService;
import com.egao.common.core.annotation.OperLog;
import com.egao.common.core.web.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * Minio上传接口
 * @author lym
 */
@Api(tags = "Minio上传文件")
@RestController
@RequestMapping("${api}")
public class MinioController {

    @Autowired
    private MinioService minioService;

    @OperLog(value = "Minio上传文件", desc = "上传文件", result = true)
    @ApiOperation(value = "上传文件-存储桶", notes = "上传到某一个存储桶内")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "file", value = "文件", required = true, dataType = "MultipartFile"),
            @ApiImplicitParam(name = "bucket", value = "存储桶名称", required = true, dataType = "string")
    })
    @PostMapping("/minio/upload/bucket")
    public JsonResult uploadBucket(@RequestParam MultipartFile file, String bucket)  {
        return minioService.uploadBucket(file, bucket);
    }

    @OperLog(value = "Minio上传文件", desc = "上传文件", result = true)
    @ApiOperation(value = "上传文件-路径", notes = "上传到默认存储桶+参数路径下")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "file", value = "文件", required = true, dataType = "MultipartFile"),
            @ApiImplicitParam(name = "path", value = "上传路径,例(单位发布招聘信息附件)：/company/recruit", required = true, dataType = "string")
    })
    @PostMapping("/minio/upload/path")
    public JsonResult uploadPath(@RequestParam MultipartFile file, String path)  {
        return minioService.uploadPath(file, path);
    }

}
